#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/2/25
# @Author: Sunny
# ========================


"""
多线程之间可以共享全局变量

缺点：会出现资源竞争，导致计算数据时，数据不准确
"""
from threading import Thread

n=100

def work1():
    """完成浇花工作"""
    global n
    for i in range(500000):
        n+=1


def work2():
    """完成打墙工作"""
    global n
    for i in range(500000):
        n+=1
t1 = Thread(target=work1)
t2 = Thread(target=work2)

t1.start()
t2.start()


#线程之间的切换执行，会导致数据计算的差异
print('n:',n)